﻿using GamFi.API.Application.Contracts.Token.GetTokenById;
using GamFi.API.Application.Contracts.Token.GetTokens;
using GamFi.API.Application.Contracts.Token.GetUserTokens;
using GamFi.API.Application.Contracts.Token.PostAddToken;
using GamFi.API.Application.Features.Queries.Token.GetTokenById;
using GamFi.API.Application.Features.Queries.Token.GetTokens;
using GamFi.API.Application.Features.Queries.Token.GetUserTokensQuery;
using GamFi.API.Application.Features.Queries.Token.PostAddToken;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GamFi.API.WEB.Controllers;

[ApiController]
[Route("api/[controller]")]
public class TokenController(IMediator mediator) : ControllerBase
{
    /// <summary>
    /// Возвращает все чейны
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    /// <returns>Все чейны</returns>
    [HttpGet("GetTokens")]
    public async Task<GetTokensResponse> GetTokens([FromQuery] GetTokensRequest request,
        CancellationToken cancellationToken)
        => await mediator.Send(new GetTokensQuery(request), cancellationToken);

    /// <summary>
    /// Возвращает чейн по ИД
    /// </summary>
    /// <param name="tokenId"></param>
    /// <param name="cancellationToken"></param>
    /// <returns>Чейн по ИД</returns>
    [HttpGet("GetTokenById/{tokenId:guid}")]
    public async Task<GetTokenByIdResponse> GetTokenById(Guid tokenId, CancellationToken cancellationToken)
        => await mediator.Send(new GetTokenByIdQuery(tokenId), cancellationToken);

    /// <summary>
    /// Возвращает токены юзера
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    /// <returns>Токены юзера</returns>
    [Authorize]
    [HttpGet("GetUserTokens")]
    public async Task<GetUserTokensResponse> GetUserTokens([FromQuery] GetUserTokensRequest request,
        CancellationToken cancellationToken)
        => await mediator.Send(new GetUserTokensQuery(request), cancellationToken);

    /// <summary>
    /// Добавление нового токена
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    [Authorize]
    [HttpPost("PostAddToken")]
    public async Task AddToken([FromBody] PostAddTokenRequest request, CancellationToken cancellationToken)
        => await mediator.Send(new PostAddTokenCommand(request), cancellationToken);
}